package com.net.xpay.common.manager.impl.invoice;

import com.google.common.base.Preconditions;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.common.manager.AbstractManager;
import com.net.xpay.common.dao.invoice.InvoiceMapper;
import com.net.xpay.common.domain.invoice.Invoice;
import com.net.xpay.common.manager.invoice.InvoiceManager;
import com.net.xpay.core.model.InvoiceSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class InvoiceManagerImpl extends AbstractManager<Invoice> implements InvoiceManager{

    @Autowired
    private InvoiceMapper mapper;


    @Override
    protected BasicMapper<Long, Invoice> getMapper() {
        return mapper;
    }

    @Override
    public List<Invoice> search(InvoiceSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(InvoiceSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public Invoice findById(Long userId, Long id) {
        Preconditions.checkArgument(userId != null && id != null);
        Invoice condition = new Invoice();
        condition.setUserId(userId);
        condition.setId(id);
        return getByCondition(condition);
    }


}
